package cn.orangelite.ai.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.orangelite.common.log.annotation.Log;
import cn.orangelite.common.log.enums.BusinessType;
import cn.orangelite.common.security.annotation.RequiresPermissions;
import cn.orangelite.ai.domain.AiConfig;
import cn.orangelite.ai.service.IAiConfigService;
import cn.orangelite.common.core.web.controller.BaseController;
import cn.orangelite.common.core.web.domain.AjaxResult;
import cn.orangelite.common.core.utils.poi.ExcelUtil;
import cn.orangelite.common.core.web.page.TableDataInfo;

/**
 * ai厂商信息配置Controller
 *
 * @author dongfaqing
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/config")
public class AiConfigController extends BaseController
{
    @Autowired
    private IAiConfigService aiConfigService;

    /**
     * 查询ai厂商信息配置列表
     */
    @RequiresPermissions("ai:config:list")
    @GetMapping("/list")
    public TableDataInfo list(AiConfig aiConfig) throws IOException {
        startPage();
        List<AiConfig> list = aiConfigService.selectAiConfigList(aiConfig);
        return getDataTable(list);
    }

    /**
     * 导出ai厂商信息配置列表
     */
    @RequiresPermissions("ai:config:export")
    @Log(title = "ai厂商信息配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiConfig aiConfig)
    {
        List<AiConfig> list = aiConfigService.selectAiConfigList(aiConfig);
        ExcelUtil<AiConfig> util = new ExcelUtil<AiConfig>(AiConfig.class);
        util.exportExcel(response, list, "ai厂商信息配置数据");
    }

    /**
     * 获取ai厂商信息配置详细信息
     */
    @RequiresPermissions("ai:config:query")
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable("configId") Long configId)
    {
        return success(aiConfigService.selectAiConfigByConfigId(configId));
    }

    /**
     * 新增ai厂商信息配置
     */
    @RequiresPermissions("ai:config:add")
    @Log(title = "ai厂商信息配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiConfig aiConfig)
    {
        return toAjax(aiConfigService.insertAiConfig(aiConfig));
    }

    /**
     * 修改ai厂商信息配置
     */
    @RequiresPermissions("ai:config:edit")
    @Log(title = "ai厂商信息配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiConfig aiConfig)
    {
        return toAjax(aiConfigService.updateAiConfig(aiConfig));
    }

    /**
     * 删除ai厂商信息配置
     */
    @RequiresPermissions("ai:config:remove")
    @Log(title = "ai厂商信息配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{configIds}")
    public AjaxResult remove(@PathVariable Long[] configIds)
    {
        return toAjax(aiConfigService.deleteAiConfigByConfigIds(configIds));
    }
}
